package com.bysj.sausys.activiti.service;

import com.bysj.sausys.activiti.common.ActivitiUtil;
import com.bysj.sausys.common.AssConst;
import com.bysj.sausys.service.ISysAssActService;
import com.bysj.sausys.util.SpringContextUtil;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.runtime.ProcessInstance;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 社团活动申请审批通过自动操作类
 *
 * @author WangZK
 */
public class AssActAuditPassServiceTask implements JavaDelegate {
    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        String processInstanceId = delegateExecution.getProcessInstanceId();
        ProcessInstance processInstance = ActivitiUtil.getProcessInstance(processInstanceId);

        // 获取业务数据
        String key = processInstance.getBusinessKey();
        if (StringUtils.isNotBlank(key)) {
            ISysAssActService sysAssActService = SpringContextUtil.getBean("sysAssActService");

            Map map = new HashMap(4);
            map.put("id", Integer.parseInt(key.split("\\.")[1]));
            map.put("auditStatus", AssConst.ASS_ACT_AUDIT_PASS.getCode());

            sysAssActService.updateStatus(map);
        }
    }
}
